'''
Created on 2012-01-17

@author: user
'''
import time
from PyDaq.Hardware.PyInsteon import InsteonPLM

plm_port = '/dev/ttyUSB0'
appl_sw1   = [22, 131, 135]
appl_sw    = [0x1b, 0x7A, 0x50]
lamp_sw    = [0x18, 0x98, 0xAA]
outdoor_sw = [0x14, 0xA1, 0x28]
imeter     = [0x19, 0x89, 0x4E]

print "Connecting to the modem on port %s" % plm_port
Plm = InsteonPLM(plm_port)

test1 = 1
test2 = 1

#print Plm.read()
if test1:
    Plm.GetIdn()
    
    #print Plm.read()
    Plm.SetSwitchON(appl_sw1)
    Plm.SetSwitchON(appl_sw)
    Plm.SetSwitchON(lamp_sw)
    Plm.SetSwitchON(outdoor_sw)
   
    time.sleep(1)
    Plm.SetSwitchOFF(appl_sw1)
    Plm.SetSwitchOFF(appl_sw)
    Plm.SetSwitchOFF(lamp_sw)
    Plm.SetSwitchOFF(outdoor_sw)
if test2:
    Plm.debug = 2    
    #Plm.read_response([0x50])
    #print Plm.GetSwitchStatus(appl_sw1)
    Plm.send_standard_cmd(lamp_sw, 17, 0)
    time.sleep(2)
    Plm.send_standard_cmd(lamp_sw, 17, 64)
    time.sleep(2)
    Plm.send_standard_cmd(lamp_sw, 17, 128)
    time.sleep(2)
    Plm.send_standard_cmd(lamp_sw, 17, 255)
    time.sleep(2)
    Plm.SetSwitchOFF(lamp_sw)
    #Plm.send_standard_cmd(appl_sw,  18, 255)

##



#Plm.read()
#Plm.send([96])

#Plm.send_standard_cmd(appl_sw1 , 25, 0)
#print Plm.read_response(0x50)
#Plm.SetSwitchON(appl_sw1)
#Plm.SetSwitchON(appl_sw)
#time.sleep(2)
#Plm.SetSwitchOFF(appl_sw1)
#Plm.SetSwitchOFF(appl_sw)
print "Test Finished"
